package org.springboot.szsrcb.controller;




import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springboot.szsrcb.entity.Req_base_info;
import org.springboot.szsrcb.entity.Req_bill;
import org.springboot.szsrcb.entity.Req_work_log;
import org.springboot.szsrcb.entity.Test_base_info;
import org.springboot.szsrcb.entity.Test_bill;
import org.springboot.szsrcb.entity.User;
import org.springboot.szsrcb.srvice.Req_bill_Service;
import org.springboot.szsrcb.srvice.Test_bill_Service;
import org.springboot.szsrcb.srvice.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;



@Controller
@RequestMapping("/test")
public class TestController_modify {

    private static final Logger logger = LoggerFactory.getLogger(TestController_modify.class);

    @Autowired
    private Req_bill_Service req_bill_Service;
    
	@Autowired
	private UserService userService;
		
	@Autowired
	private Test_bill_Service test_bill_Service;

	@RequestMapping("/test_mgmt")
	public String test_mgmt(HttpSession httpSession) {
		String login_name = (String) httpSession.getAttribute("login_name");
		if (login_name != null) {
		logger.info("test_mgmt");
		// model.addAttribute("name", name);
		return "test_list_mgnt";
		} else {
			logger.info("access login page.");
			return "/login";
		}
	}

	@RequestMapping("/test_modify_detail")
	public String test_modify_detail(HttpServletRequest request,Model model,HttpSession httpSession) {
		
		logger.info("/test/test_modify_detail");
		String test_id = request.getParameter("test_id");
		//Req_base_info m=new Req_base_info();		
		model.addAttribute("test_v",test_id);	
		String login_name=(String) httpSession.getAttribute("login_name");  
		User u =userService.search_a_user(login_name);
		//String role=u.getRole();
		//Req_bill req=req_bill_Service.req_bill_search_by_id(test_id);
		Test_bill test=test_bill_Service.search_a_test_bill_by_id(test_id);
		
		String g_status=test.getTest_status();
		
		/*String check_role1="部门主管领导";
		String check_role2="项目管理中心负责人";
		String check_role3="业务方案中心负责人";*/
		String check_value1="已接收";
		String check_value2="已退回";
		if (u != null) {
		//	boolean is_leader=userService.is_leader(u.getName());
		
		//if (is_leader){
			model.addAttribute("is_base_info","true");
			if(g_status.equals(check_value1)||g_status.equals(check_value2)){
				model.addAttribute("is_team_info","false");	
				model.addAttribute("is_test_info","false");	
				model.addAttribute("is_workload_info","false");
				model.addAttribute("is_work_log_info","false");
			}else{
				model.addAttribute("is_team_info","true");	
				model.addAttribute("is_test_info","true");	
				model.addAttribute("is_workload_info","true");
				model.addAttribute("is_work_log_info","true");
			}
		/*}else{
			model.addAttribute("is_base_info","true");
			
			if(g_status.equals(check_value1)||g_status.equals(check_value2)){
				model.addAttribute("is_test_info","false");
				model.addAttribute("is_team_info","false");	
				model.addAttribute("is_workload_info","false");
				model.addAttribute("is_work_log_info","false");
			}else{
				boolean is_test_head=test_bill_Service.check_is_test_head(u.getName(),test_id);						
				if (is_test_head) {
					model.addAttribute("is_workload_info","true");
					model.addAttribute("is_test_info","true");	
				} else {
					model.addAttribute("is_workload_info","false");
					model.addAttribute("is_test_info","false");	
				}		
				model.addAttribute("is_team_info","true");
				model.addAttribute("is_test_info","true");	
				model.addAttribute("is_workload_info","true");
				model.addAttribute("is_work_log_info","true");
			}
			
		}	*/	
		return "test_modify_detail";
		}else{
			return "login";
		}
		
	}

	@RequestMapping("/test_modify_detail_base_info")
	public String test_modify_detail_base_info(HttpServletRequest request,Model model,HttpSession httpSession) {
		logger.info("test_modify_detail_base_info");
		String test_id = request.getParameter("test_id");				
		model.addAttribute("test_id",test_id);			
		
		String login_name=(String) httpSession.getAttribute("login_name");  
		User u =userService.search_a_user(login_name);		
		boolean is_leader=userService.is_leader(u.getName());
		model.addAttribute("is_leader", is_leader);
		/*boolean is_test_head=test_bill_Service.check_is_test_head(u.getName(),test_id);						
		if (is_test_head) {
			is_leader=true;
			model.addAttribute("is_leader", is_leader);
		}*/
		return "test_modify_detail_base_info";
	}

	@RequestMapping("/test_modify_detail_test_info")
	public String test_modify_detail_test_info(HttpServletRequest request,Model model) {
		logger.info("test_modify_detail_test_info");
		String test_id = request.getParameter("test_id");				
		model.addAttribute("test_id",test_id);	
		return "test_modify_detail_test_info";
	}

	@RequestMapping("/test_modify_detail_team_info")
	public String test_modify_detail_team_info(HttpServletRequest request,Model model) {
		logger.info("test_modify_detail_team_info");
		String test_id = request.getParameter("test_id");				
		model.addAttribute("test_id",test_id);	
		return "test_modify_detail_team_info";
	}

	@RequestMapping("/test_modify_detail_workload_info")
	public String test_modify_detail_workload_info(HttpServletRequest request,Model model) {
		logger.info("test_modify_detail_workload_info");
		String test_id = request.getParameter("test_id");
		//Test_base_info test_base_info= test_bill_Service.search_a_test_base_info_by_testid(test_id);
		//float test_plan_workload=test_base_info.getTest_workload();
		model.addAttribute("test_id",test_id);
	//	model.addAttribute("test_plan_workload",test_plan_workload);
		return "test_modify_detail_workload_info";
	}

	@RequestMapping("/test_modify_detail_work_log_info")
	public String test_modify_detail_work_log_info(HttpServletRequest request,Model model) {
		logger.info("test_modify_detail_work_log_info");
		String test_id = request.getParameter("test_id");				
		model.addAttribute("test_id",test_id);	
		return "test_modify_detail_work_log_info";
	}
	
	
	
	
	
}
